#include "StateIntroduction.h"

#include "effects/Hollywood.h"
#include "StringUtility.h"

StateIntroduction::StateIntroduction()
{
    lives = 0;
    levelData = NULL;

    nameText.loadFont("fonts/unispace.ttf",24);
    nameText.setColour(WHITE);
    timer.start(4000);

    GFX::setClearColour(BLACK);

    EFFECTS->fadeIn(1000,BLACK);
}

StateIntroduction::~StateIntroduction()
{
    delete levelData;
}

void StateIntroduction::userInput()
{
    input->update();

    // This is triggered when the user presses the close button (X) on a PC and ensures it actually closes the window
#ifdef PLATFORM_PC
    if(input->isQuit())
    {
        nullifyState();
        return;
    }
#endif
}

void StateIntroduction::update()
{
    timer.update();
    levelData->bg.update();
    levelData->icon.update();

    if (timer.hasFinished())
        setNextState(STATE_BASE);

    EFFECTS->update();
}

void StateIntroduction::render()
{
    GFX::clearScreen();

    levelData->bg.render();

    nameText.setPosition(50,50);
    nameText.print(levelData->name);
    nameText.setPosition(50,100);
    nameText.print(levelData->description);
    nameText.setPosition(50,300);
    nameText.print("Lives x" + StringUtility::intToString(lives));

    levelData->icon.render();

    EFFECTS->render();
}
